fix(proxy): clear SNI peek deadline before relay, fix socket leaks#15
Merged
nnemirovsky merged 1 commit intomainfrom Apr 10, 2026
Merged
fix(proxy): clear SNI peek deadline before relay, fix socket leaks#15nnemirovsky merged 1 commit intomainfrom
nnemirovsky merged 1 commit intomainfrom
Conversation
The 10-second read deadline set for SNI peeking in the SNI-deferred path was cleared via defer, which only runs when handleConnect returns. Since handleConnect blocks in relayData for the connection lifetime, the deadline persisted and killed every SNI-deferred connection after 10 seconds. This caused streaming API responses to be truncated (manifesting as OpenAI "terminated" errors), tool call fetches to fail, and periodic TLS handshake failures on chatgpt.com. Fix: clear the deadline explicitly after SNI peek completes, before the relay phase begins. Also fixes two secondary issues: - relayData socket leak: when the first relay direction completed, the function could block indefinitely waiting for the second goroutine if goproxy held the MITM connection open. Close writer and set a read deadline on target to force cleanup. Eliminates CLOSE_WAIT socket accumulation (75 leaked sockets observed). - goproxy Transport stale connections: the MITM proxy Transport had no IdleConnTimeout, causing dead pooled connections to persist indefinitely. Add IdleConnTimeout (90s) and MaxIdleConnsPerHost (4). - goproxy log noise: suppress expected broken pipe and handshake EOF warnings via a filtered logger. These are normal for short-lived polling connections (Telegram getUpdates).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deferwhich only ran whenhandleConnectreturned, buthandleConnectblocks inrelayDatafor the connection lifetime.relayDataCLOSE_WAIT socket leak (75 leaked sockets observed on production server) by closing writer and setting a read deadline on target when the first relay direction completes.IdleConnTimeout(90s) andMaxIdleConnsPerHost(4) to goproxy Transport to prevent stale pooled connections.Test plan
go test ./...passesgolangci-lint runclean